package com.sz.biz.common.customer.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.sz.biz.common.customer.entity.CustomerMessageType;

import java.util.*;

/**
 * Function: TODO: ADD FUNCTION <br>
 * Author: Johnboy <br>
 * Date: 2017-08-10 17:28:00
 */
public class CustomerMessageRelTypeItem {

    private int id;
    private String name;
    private String code;
    private Integer parentId;
    private Boolean isLeaf;
    private Integer ordinal;
    private Boolean isDeleted;
    private String description;
    private Date createTime;
    private Date lastUpdateTime;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Boolean selected;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<NoticeMessageTypeItem> messageTypeItems;
    private List<CustomerMessageRelTypeItem> children = new ArrayList<>();//菜单中包含的子节点

    public CustomerMessageRelTypeItem(String name, String code, Integer parentId, Boolean isLeaf, Integer ordinal, Boolean isDeleted, String description, Date createTime, Date lastUpdateTime) {
        this.name = name;
        this.code = code;
        this.parentId = parentId;
        this.isLeaf = isLeaf;
        this.ordinal = ordinal;
        this.isDeleted = isDeleted;
        this.description = description;
        this.createTime = createTime;
        this.lastUpdateTime = lastUpdateTime;
    }

    public CustomerMessageRelTypeItem(CustomerMessageType customerMessageType) {
        this.id = customerMessageType.getId();
        this.name = customerMessageType.getName();
        this.code = customerMessageType.getCode();
        this.parentId = customerMessageType.getParentId();
        this.isLeaf = customerMessageType.getIsLeaf();
        this.ordinal = customerMessageType.getOrdinal();
        this.isDeleted = customerMessageType.getIsDeleted();
        this.description = customerMessageType.getDescription();
        this.createTime = customerMessageType.getCreateTime();
        this.lastUpdateTime = customerMessageType.getLastUpdateTime();
    }

    public CustomerMessageRelTypeItem() {
    }

    public void addChild(CustomerMessageRelTypeItem child) {
        this.children.add(child);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Boolean getLeaf() {
        return isLeaf;
    }

    public void setLeaf(Boolean leaf) {
        isLeaf = leaf;
    }

    public Integer getOrdinal() {
        return ordinal;
    }

    public void setOrdinal(Integer ordinal) {
        this.ordinal = ordinal;
    }

    public Boolean getDeleted() {
        return isDeleted;
    }

    public void setDeleted(Boolean deleted) {
        isDeleted = deleted;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public List<CustomerMessageRelTypeItem> getChildren() {
        return children;
    }

    public void setChildren(List<CustomerMessageRelTypeItem> children) {
        this.children = children;
    }

    public void sort() {
        Collections.sort(this.children, new Comparator<CustomerMessageRelTypeItem>() {
            @Override
            public int compare(CustomerMessageRelTypeItem o1, CustomerMessageRelTypeItem o2) {
                return (o1.getOrdinal() > o2.getOrdinal()) ? 1 : -1;
            }
        });
        for (CustomerMessageRelTypeItem item : children) {
            item.sort();
        }
    }

    public List<NoticeMessageTypeItem> getMessageTypeItems() {
        return messageTypeItems;
    }

    public void setMessageTypeItems(List<NoticeMessageTypeItem> messageTypeItems) {
        this.messageTypeItems = messageTypeItems;
    }

    public boolean hasChild() {
        return this.children != null && this.children.size() > 0;
    }
}
